package com.ruoyi.enterprise.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.enterprise.domain.SJob;
import com.ruoyi.enterprise.service.ISJobService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业岗位信息Controller
 * 
 * @author jeffery
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/enterprise/position")
public class SJobController extends BaseController
{
    @Autowired
    private ISJobService sJobService;

    /**
     * 查询企业岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(SJob sJob)
    {
        startPage();
        List<SJob> list = sJobService.selectSJobList(sJob);
        return getDataTable(list);
    }

    /**
     * 导出企业岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:export')")
    @Log(title = "企业岗位信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SJob sJob)
    {
        List<SJob> list = sJobService.selectSJobList(sJob);
        ExcelUtil<SJob> util = new ExcelUtil<SJob>(SJob.class);
        return util.exportExcel(list, "企业岗位信息数据");
    }

    /**
     * 获取企业岗位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return AjaxResult.success(sJobService.selectSJobByJobId(jobId));
    }

    /**
     * 新增企业岗位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:add')")
    @Log(title = "企业岗位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SJob sJob)
    {
        return toAjax(sJobService.insertSJob(sJob));
    }

    /**
     * 修改企业岗位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:edit')")
    @Log(title = "企业岗位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SJob sJob)
    {
        return toAjax(sJobService.updateSJob(sJob));
    }

    /**
     * 删除企业岗位信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:position:remove')")
    @Log(title = "企业岗位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(sJobService.deleteSJobByJobIds(jobIds));
    }

    @GetMapping(value = "/getJobInfoByCompanyId/{companyId}")
    public AjaxResult getJobInfoByCompanyId(@PathVariable("companyId") Long companyId)
    {
        List<SJob> jobList = sJobService.selectJobByCompanyId(companyId);
        return AjaxResult.success(jobList);
    }

}
